package com.example.demo.service.impl;

import com.example.demo.bean.Order;
import com.example.demo.bean.User;
import com.example.demo.bean.view.OrderView;
import com.example.demo.mapper.OrderMapper;
import com.example.demo.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("OrderService")
public class OrderServiceImpl implements OrderService {
    @Autowired(required=true)
    @Qualifier("OrderMapper")
    private OrderMapper orderMapper;
    @Override
    public boolean insertOrder(Order order) {
        return orderMapper.insertOrder(order.getOrderNum(), order.getBuyerNum(),order.getSellerNum(),order.getTimestamp(),order.getOrderCondition(),order.getDeleteFlag(),order.getGoodsNum(),order.getNumOfGoods());

    }

    @Override
    public boolean deleteOrderForAdmin(Order order) {
        return orderMapper.deleteOrderByAdmin(order.getOrderNum());
    }

    @Override
    public boolean deleteOrderForUser(Order preOrder, Order laOrder) {
        return orderMapper.deleteOrderByUser(preOrder.getOrderNum(),laOrder.getDeleteFlag());

    }

    @Override
    public boolean updateOrder(Order preOrder, Order laOrder) {
        return orderMapper.updateOrder(preOrder.getOrderNum(), laOrder.getOrderCondition(), laOrder.getNumOfGoods());

    }

    @Override
    public List<Order> findAllOrder() {
        List<Order> orderList = orderMapper.findAllOrder();
        if(orderList != null)
        {
            return orderList;
        }
        else
        {
            return null;
        }
    }

    @Override
    public List<OrderView> findOrderByBuyerNum(User buyer) {
        List<OrderView> orderList = orderMapper.findOrderByBuyerNum(buyer.getUserNum());
        if(orderList != null)
            return orderList;
        else
        {
            return null;
        }
    }

    @Override
    public List<OrderView> findOrderBySellerNum(User seller) {
        List<OrderView> orderViewList = orderMapper.findOrderBySellerNum(seller.getUserNum());
        if(orderViewList != null)
        {
            return orderViewList;
        }
        else
        {
            return null;
        }
    }

    @Override
    public OrderView findOrderByOrderNum(Order order) {
        OrderView orderView = orderMapper.findOrderByOrderNum(order.getOrderNum());
        if(orderView != null)
        {
            return orderView;
        }
        else
        {
            return null;
        }
    }

    @Override
    public List<OrderView> findAllOrderView() {
        List<OrderView> orderViewList = orderMapper.findAllOrderView();
        if(orderViewList != null)
        {
            return orderViewList;
        }
        else
        {
            return null;
        }
    }
}
